package com.lance.core.launch;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;

/**
 * @author lancecong
 * @version 1.0
 * @ClassName StartedEventListener
 * @DESCRIPTION TODO
 * @create 2019-06-28 18:45
 **/
@Slf4j
@Configuration
public class StartedEventListener {

    public void startedServer(WebServerInitializedEvent event){
        Environment environment = event.getApplicationContext().getEnvironment();
        String appName = environment.getProperty("spring.application.name").toUpperCase();
        int port = event.getWebServer().getPort();
        String profile = StringUtils.arrayToCommaDelimitedString(environment.getActiveProfiles());
        log.info("【{}】 项目启动完成,端口为【{}】,环境【{}】",appName,port,profile);

    }
}
